/**
 * 这里存放的是对账户的操作。
 * 注册
 * 登录
 */
import {
  ajaxTcbCloud,
  ajaxTcbCloudExtends,
  ajaxTcbCloudWithoutToken
} from "@/utils/cloud";
import { successResponseType, failRejectType } from "CustomTypes";

/**
 * 检查用户名是否重复。
 */
export const checkAccount = (data: string): Promise<any> =>
  ajaxTcbCloudExtends("/login/checkAccount", { data }, true);
/**
 * 注册账号密码
 */
export const registUser = async (
  username: string,
  password: string,
  aesKey: string
): Promise<successResponseType | failRejectType> =>
  ajaxTcbCloudWithoutToken("/login/regist", { username, password, aesKey });
/**
 * 登录
 */
export const loginAccount = async (
  username: string,
  password: string,
  aesKey: string
): Promise<successResponseType | failRejectType> =>
  ajaxTcbCloudWithoutToken("/login/index", { username, password, aesKey });
/**
 * 登出，这里尝试使用自己定义的token。
 */
export const logoutAccount = async (
  username: string
): Promise<successResponseType | failRejectType> =>
  ajaxTcbCloud("/login/logout", { username });
